package com.linwen.excise.leetcode;

public class _680验证回文字符串2 {
    public static void main(String[] args) {
        String s = "abc";
        System.out.println(validPalindrome(s));

    }
    public static boolean validPalindrome(String s) {
        int left = 0;
        int right = s.length()-1;
        char[] chars = s.toCharArray();
        while (left<right){
            if(chars[left]==chars[right]){
                left++;
                right--;
            }else{
                return validPalindrome(chars,left+1,right)||validPalindrome(chars,left,right-1);
            }
        }
        return true;
    }

    private static boolean validPalindrome(char[] chars, int left, int right) {
        while (left<right){
            if(chars[left]==chars[right]){
                left++;
                right--;
            }else{
            return false;
            }
        }
        return true;
    }
}
